<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @author Walter Tamboer
 * @package Framework03
 */

/**
 * This class is able to render pages in a debug view.
 */
class FW_View_Debug extends FW_View_Abstract
{
    /**
     * @var array An array with data to debug.
     */
    private $data = array();

    /**
     * Initializes a new instance of this class.
     * @param array $data An array with data to debug.
     */
    public function __construct(array $data = array())
    {
        $this->data = $data;
    }
    
    /**
     * Prints the value as a debug value.
     * @param mixed $value
     */
    private function debug($value)
    {
        print_r($value);
    }

    /**
     * Renders the view to the screen.
     * @param FW_Controller_Action $controller The controller that wants the rendering to be done.
     * @param string $actionName The name of the action that wants the rendering to be done.
     */
    public function render(FW_Controller_Action $controller, $actionName)
    {
		echo '<h1>DebugRenderDevice</h1>';

		if (count($this->data) > 0)
		{
			echo '<h2>$this->data</h2>';
			echo '<table width="100%" border="1">';
			foreach ($this->data as $key => $value)
			{
				echo '<tr>';
				echo '<td width="15%" valign="top">' . $key . '</td>';
				echo '<td width="85%" valign="top">';
				$this->debug($value);
				echo '</td>';
				echo '</tr>';
			}
			echo '</table>';
		}

		if (isset($_GET) && count($_GET) > 0)
		{
			echo '<h2>$_GET</h2>';
			echo '<table width="100%" border="1">';
			foreach ($_GET as $key => $value)
			{
				echo '<tr>';
				echo '<td width="15%" valign="top">' . $key . '</td>';
				echo '<td width="85%" valign="top">';
				$this->debug($value);
				echo '</td>';
				echo '</tr>';
			}
			echo '</table>';
		}

		if (isset($_POST) && count($_POST) > 0)
		{
			echo '<h2>$_POST</h2>';
			echo '<table width="100%" border="1">';
			foreach ($_POST as $key => $value)
			{
				echo '<tr>';
				echo '<td width="15%" valign="top">' . $key . '</td>';
				echo '<td width="85%" valign="top">';
				$this->debug($value);
				echo '</td>';
				echo '</tr>';
			}
			echo '</table>';
		}

		if (isset($_SESSION) && count($_SESSION) > 0)
		{
			echo '<h2>$_SESSION</h2>';
			echo '<table width="100%" border="1">';
			foreach ($_SESSION as $key => $value)
			{
				echo '<tr>';
				echo '<td width="15%" valign="top">' . $key . '</td>';
				echo '<td width="85%" valign="top">';
				$this->debug($value);
				echo '</td>';
				echo '</tr>';
			}
			echo '</table>';
		}

		if (isset($_COOKIE) && count($_COOKIE) > 0)
		{
			echo '<h2>$_COOKIE</h2>';
			echo '<table width="100%" border="1">';
			foreach ($_COOKIE as $key => $value)
			{
				echo '<tr>';
				echo '<td width="15%" valign="top">' . $key . '</td>';
				echo '<td width="85%" valign="top">';
				$this->debug($value);
				echo '</td>';
				echo '</tr>';
			}
			echo '</table>';
		}

		echo '<h2>$_SERVER</h2>';
		echo '<table width="100%" border="1">';
		foreach ($_SERVER as $key => $value)
		{
			echo '<tr>';
			echo '<td width="15%" valign="top">' . $key . '</td>';
			echo '<td width="85%" valign="top">';
			$this->debug($value);
			echo '</td>';
			echo '</tr>';
		}
		echo '</table>';
    }
}
